package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.entity.SampleStorageLocation;
import cn.stylefeng.guns.modular.business.reqeust.SampleStorageLocationRequest;
import cn.stylefeng.guns.modular.business.service.ISampleStorageLocationService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  样本数据存储位置前端控制器
 * </p>
 *
 * @author generator
 * @since 2024-07-12
 */
@RestController
@ApiResource(path = "/api/service/sampleStorageLocation", name = "样本数据存储位置", resBizType = ResBizTypeEnum.BUSINESS)
public class SampleStorageLocationController {

    @Autowired
    private ISampleStorageLocationService sampleStorageLocationService;

    @PostResource(name = "新增", path = "/add")
    public ResponseData<?> add(@RequestBody @Validated(BaseRequest.add.class) SampleStorageLocationRequest sampleStorageLocationRequest){
        SampleStorageLocation sampleStorageLocation = new SampleStorageLocation();
        BeanUtils.copyProperties(sampleStorageLocationRequest, sampleStorageLocation);
        sampleStorageLocationService.save(sampleStorageLocation);
        return new SuccessResponseData<>();
   }

    @GetResource(name = "删除", path = "/delete")
    public ResponseData<?> del( @Validated(BaseRequest.delete .class) SampleStorageLocationRequest request) {
         sampleStorageLocationService.removeById(request.getId());
        return new SuccessResponseData<>();
    }

    @PostResource(name = "更新", path = "/edit")
    public ResponseData<?> update(@RequestBody @Validated(BaseRequest.edit.class) SampleStorageLocationRequest sampleStorageLocationRequest){
        SampleStorageLocation sampleStorageLocation = new SampleStorageLocation();
        BeanUtils.copyProperties(sampleStorageLocationRequest, sampleStorageLocation);
         sampleStorageLocationService.updateById(sampleStorageLocation);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "详情", path = "/detail")
    public ResponseData<?> detail(@Validated(BaseRequest.detail.class) SampleStorageLocationRequest request) {
        SampleStorageLocation sampleStorageLocation = sampleStorageLocationService.getById(request.getId());
        return new SuccessResponseData<>(sampleStorageLocation);
    }

    @GetResource(name = "列表", path = "/list")
    public ResponseData<?> list(@Validated(BaseRequest.list.class) SampleStorageLocationRequest request) {
        List<SampleStorageLocation> list = sampleStorageLocationService.list(Wrappers.<SampleStorageLocation>lambdaQuery().eq(
                SampleStorageLocation::getSampleDataId, request.getSampleDataId()));
        return new SuccessResponseData<>(list);
    }

    /**
     * 分页和搜索
     *
     * @param sampleStorageLocationRequest
     * @return
     */
    @GetResource(name = "分页", path = "/page")
    public ResponseData<PageResult<SampleStorageLocation>> page(SampleStorageLocationRequest sampleStorageLocationRequest) {
        PageResult<SampleStorageLocation> page = sampleStorageLocationService.findPage(sampleStorageLocationRequest);
        return new SuccessResponseData<>(page);
    }
}
